package com.example.springbootdemo.scanner;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;

import java.util.Set;

public class CustomClassPathScanner extends ClassPathBeanDefinitionScanner {
    public CustomClassPathScanner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    @Override
    protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
        //直接返回true则表示包下所有候选类都可以作为bean定义放入spring
        //这里返回带有指定注解的类更进一步的看效果
        return beanDefinition.getMetadata().hasAnnotation("com.example.springbootdemo.scanner.CustomAnno");
    }

    @Override
    protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
        return super.doScan(basePackages);
    }
}
